package sg.edu.nus.iss.phoenix.schedule.entity;

import java.sql.Time;
import java.util.Calendar;
import java.util.Date;

import sg.edu.nus.iss.phoenix.utils.CommonUtils;
/**
 * 
 * @author Sanghrajka Vipul - A0092656W
 *
 */

/* @class 
 * This class is utility class which has generic Calendar methods used across the programs.
 * All Methods are static as no state maintenance is required.
 */
public class Utility {


	public static final int CREATE_SCHEDULE = 1;
	public static final int COPY_SCHEDULE = 2;
	public static final int DELETE_SCHEDULE = 3;
	public static final int MODIFY_SCHEDULE = 4;
	public static int WEEK_OF_YEAR=Calendar.getInstance().get(Calendar.WEEK_OF_YEAR);
	public static java.util.Date now = new java.util.Date();
	
	public static java.sql.Date getDateforWeekDayYear(int week, int day, int year){
		Calendar calendar = Calendar.getInstance();
		calendar.clear();
		calendar.set(Calendar.WEEK_OF_YEAR, 30);
		calendar.set(Calendar.YEAR, 2012);
		calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		// Now get the first day of week.
		Date date = calendar.getTime();
		System.out.println(date);
		return CommonUtils.changeToSQLDate(date);
	}
	
	/**
	 * This is a tstic method to return the time from the variables 
	 * hours and minutes.
	 * The native implementation is using Calendar.
	 * @param hh
	 * @param mm
	 * @return
	 */
	public static java.sql.Time getTimeOfDay(int hh, int mm){
	Calendar calendar = Calendar.getInstance();
	calendar = Calendar.getInstance();
	
	calendar.set(Calendar.HOUR_OF_DAY, hh);
	calendar.set(Calendar.MINUTE, mm);
	calendar.set(Calendar.SECOND, 0);
	//calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
	java.sql.Time time = new Time(calendar.getTime().getTime());
	System.out.println(time);
	return time;
	}
	
	
	/**
	 * This method returns the Week number of the year based on the date
	 * @param date
	 * @return
	 */
	public static int WeekofYearFromDay(java.sql.Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.WEEK_OF_YEAR;
		
	}
	
	/**
	 * This methods generates 24hrs hr format based on the time
	 * @param time
	 * @return
	 */
	
	public static int getHHfromTime(java.sql.Time time){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
		return calendar.HOUR_OF_DAY;
		
	}
	
	/**
	 * This methods generates minutes mm format based on the time
	 * @param time
	 * @return
	 */
	public static int getMMfromTime(java.sql.Time time){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(time);
		return calendar.MINUTE;
		
	}
	
	
/**
 * This method generates the DAY of the week in number based on the date
 * @param date
 * @return
 */
	public static int DayofTheWeekFromDate(java.sql.Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar.DAY_OF_WEEK;
		
	}
	
	/**
	 * this method returns the calendar week number.
	 * @return
	 */
	public static int getCurrentWeek(){
		Calendar calendar = Calendar.getInstance();
		return calendar.WEEK_OF_YEAR;
		//return calendar.DAY_OF_WEEK;
		
	}
}
